@extends('admin.layouts.head')
@section('content')
    <body>
    <div id="app">
        <div class="wrapper -header-fixed">

        @include('admin.layouts.navbar')
        @include('admin.layouts.sidebar')

        <!-- 内容页开始-->
            <div class="content-container">

                <div class="container-fluid">
                    <div class="page-content">

                        <nav aria-label="breadcrumb">
                            <ol class="breadcrumb">
                                <li class="breadcrumb-item"><a href="{{ route('dashboard') }}">仪表盘</a></li>
                                <li class="breadcrumb-item active" aria-current="page">图片管理</li>
                            </ol>
                        </nav>

                        <div class="card">
                            <div class="card-body">

                                <div class="form-group">
                                    <div class="row">
                                        <div class="col-lg-10 col-md-7" style="margin-bottom: 10px">
                                        <!-- <a href="{{route('promotion.create')}}" class="btn btn-primary"> 添加 </a> -->
                                            <a href="javascript:void(0);" class="btn btn-danger" onclick="operation_tip2(-1)"> 批量删除 </a>
                                        </div>
                                        <div class="col-lg-2 col-md-5">
                                            <div class="input-group">
                                                <input type="text" class="form-control" id="search" placeholder="搜索...">
                                                <button class="btn btn-primary" onclick="window.location.href = '{{ route('admin.banner.image.index') }}?search='+$('#search').val()">
                                                    搜索
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="table-responsive">
                                    <table class="table table-sm table-hover text-center">
                                        <thead>
                                        <tr>
                                            <th>
                                                <div class="custom-control custom-checkbox">
                                                    <input type="checkbox" class="custom-control-input" name="selectAll" id="selectAll">
                                                    <label class="custom-control-label" for="selectAll"></label>
                                                </div>
                                            </th>
                                            <th style="min-width:50px;">ID</th>
                                            <th style="min-width:200px;">图片地址</th>
                                            <th style="min-width:150px;">跳转地址</th>
                                            <th style="min-width:200px;">设置时间</th>
                                            <th style="min-width:100px;">设置人</th>
                                            <th style="min-width:110px;">操作</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        @foreach($image as $key => $data)
                                            <tr>
                                                <td>
                                                    <div class="custom-control custom-checkbox">
                                                        <input type="checkbox" class="custom-control-input" name="checkboxVal" id="{{$data->id}}" value="{{$data->id}}">
                                                        <label class="custom-control-label" for="{{$data->id}}"></label>
                                                    </div>
                                                </td>
                                                <td>{{($image->currentPage()-1)*16+1+$key}}</td>
                                                <td><a href="{{$data->image}}" target="_blank">{{$data->image}}</a></td>
                                                <td><a href="{{$data->url}}" target="_blank">{{$data->url}}</a></td>
                                                <td>{{$data->set_time}}</td>
                                                <td>{{$data->set_people}}</td>
                                                <td>
                                                    <a href="{{ route('admin.banner.image.edit',$data->id) }}" class="btn btn-primary btn-sm">修改</a>
                                                    <a href="javascript:void(0);" class="btn btn-danger btn-sm" onclick="operation_tip2({{$data->id}})">删除</a>
                                                </td>
                                            </tr>
                                        @endforeach
                                        </tbody>
                                    </table>
                                </div>

                            </div> <!-- .card-body -->

                            <!-- 分页 -->
                            <nav class="page-card-pagination">
                                <ul class="pagination justify-content-center">
                                    {{$image->Links()}}
                                </ul>
                            </nav>
                            <!-- end分页 -->

                        </div> <!-- .card -->

                    </div> <!-- .page-content -->
                </div> <!-- .container-fluid -->
            </div> <!-- .content-container -->
        </div> <!-- .wrapper -->
    </div> <!-- #app -->
    <script src="{{ mix('js/app.js') }}"></script>
    <script src="{{ asset('/js/main.js') }}"></script>
    <script>
        // 全选
        $('input[name="selectAll"]').on("click",function(){
            if($(this).is(':checked')){
                $('input[name="checkboxVal"]').each(function(){
                    $(this).prop("checked",true);
                });
            }else{
                $('input[name="checkboxVal"]').each(function(){
                    $(this).prop("checked",false);
                });
            }
        });

        let isLoading = false;

        //删除
        function submit(id) {

            obj = document.getElementsByName("checkboxVal");
            check_val = [];
            for (k in obj) {
                if (obj[k].checked) {
                    check_val.push(obj[k].value);
                }
            }

            var checkboxVal;
            if( id === -1){
                checkboxVal = check_val;
            }else {
                checkboxVal = id;
            }

            if (checkboxVal =='') {
                toast('您还没有选择要删除的对象。');
                return false
            }

            if (isLoading === false) {
                isLoading = true;

                axios.delete('{{route('admin.banner.image.destroy','').'/'}}'+checkboxVal)
                    .then(function (response) {
                        isLoading = false;
                        toast_tip2(response.data.message, window.location.href);
                    })
                    .catch(function (error) {
                        isLoading = false;
                        $.each(error.response.data.errors, function (index, object) {
                            toast(object[0]);
                            return false;
                        });
                    })
            }

        }
    </script>
    </body>

@endsection
